<?php
namespace App\Utils\Logic\Ly;
use App\Models\Ly\Agent;
use App\Utils\Lib\Redis;

class Agentlogic
{
    public static function search($keyword,$phone)
    {
        $where=[];
        if(isset($keyword) && !empty($keyword))
        {
            $where[]=['name','like',"%$keyword%"];
        }
        if(isset($phone) && !empty($phone))
        {
            $where[]=['phone','like',"%$phone%"];
        }
        $data=Agent::getList($where)->paginate(3);
        return $data->toArray();
    }

    /**
     * 经纪人详情
     * @param $id
     * @return bool|false|mixed|string
     * @throws \RedisException
     * @name ly
     */
    public static function detail($id)
    {
        $Agentdata= \App\Models\Agent::getOne($id);
        $Agentdata = json_encode($Agentdata,JSON_UNESCAPED_UNICODE);
        $redis = Redis::createRedisObject();
        $redis->select(15);
        $key = 'details:'.$id;
        $data=  $redis->hgetAll($id);
        if (empty($data)){
            $redis->set($key, $Agentdata);
            //永久性缓存
            $redis->persist($key);
            $Agentdata = $redis->GetRedis($key);
        }
        return $Agentdata;
    }
}
